home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0071_Handling file Attributes.pas < prev   
Pascal/Delphi Source File  |  1995-02-28  |  5KB  |  108 lines

  1. {
  2. Here are some routines for Hiding files, making read only files and
  3. stuff.  Let me know what you think.  Any comments, criticism, or rude
  4. remarks are welcome.
  5.  
  6. { ********************************************************** }
  7. { *********************** Files Unit *********************** }
  8. { ********************************************************** }
  9. { **************** Written by: Rick Haines ***************** }
  10. { ********************************************************** }
  11. { ***************** Last Revised 02/02/95 ****************** }
  12. { ********************************************************** }
  13.  
  14. Unit Files;
  15.  
  16. Interface
  17.  
  18.  { Note: All FileNames MUST end in a null Char }
  19.  { EX:   HideFile(FileName+#0);                }
  20.  { EX:   HideFile('MyFile.Exe'+#0);            }
  21.  
  22.  Function HideFile(FileName : String) : Byte;     { Hide FileName }
  23.  Function SystemFile(FileName : String) : Byte;   { Make FileName a System File }
  24.  Function ReadOnlyFile(FileName : String) : Byte; { Make FileName ReadOnly }
  25.  Function NormalFile(FileName : String) : Byte;   { Make FileName a Normal File }
  26.  Function FileAttributes(FileName : String) : Integer; { Returns Attributes of   }
  27.  
  28. Implementation
  29.  
  30.  Function HideFile(FileName : String) : Byte; Assembler;
  31.   Asm
  32.    Push DS           { Push Data Segment                  }
  33.    LDS DX, FileName  { Nul Terminated String of FileName  }
  34.    Inc DX            { Get Rid Of Length Byte             }
  35.    Mov AH, 43h       { Dos Function 43h, File Change Mode }
  36.    Mov AL, 1         { Change Attributes                  }
  37.    Mov CX, 2         { Bit 1, Hide It                     }
  38.    Int 21h           { Call Dos                           }
  39.    JC @Done          { See if there was an error          }
  40.    Mov AL, 0         { If Not, Then No Error              }
  41.   @Done:
  42.    Pop DS            { Pop Data Segment                   }
  43.   End;
  44.  
  45.  Function SystemFile(FileName : String) : Byte; Assembler;
  46.   Asm
  47.    Push DS           { Push Data Segment                  }
  48.    LDS DX, FileName  { Nul Terminated String of FileName  }
  49.    Inc DX            { Get Rid Of Length Byte             }
  50.    Mov AH, 43h       { Dos Function 43h, File Change Mode }
  51.    Mov AL, 1         { Change Attributes                  }
  52.    Mov CX, 4         { Bit 3, System File                 }
  53.    Int 21h           { Call Dos                           }
  54.    JC @Done          { See if there was an error          }
  55.    Mov AL, 0         { If Not, Then No Error              }
  56.   @Done:
  57.    Pop DS            { Pop Data Segment                   }
  58.   End;
  59.  
  60.  Function ReadOnlyFile(FileName : String) : Byte; Assembler;
  61.   Asm
  62.    Push DS           { Push Data Segment                  }
  63.    LDS DX, FileName  { Nul Terminated String of FileName  }
  64.    Inc DX            { Get Rid Of Length Byte             }
  65.    Mov AH, 43h       { Dos Function 43h, File Change Mode }
  66.    Mov AL, 1         { Change Attributes                  }
  67.    Mov CX, 1         { Bit 0, Read Only                   }
  68.    Int 21h           { Call Dos                           }
  69.    JC @Done          { See if there was an error          }
  70.    Mov AL, 0         { If Not, Then No Error              }
  71.   @Done:
  72.    Pop DS            { Pop Data Segment                   }
  73.   End;
  74.  
  75.  Function NormalFile(FileName : String) : Byte; Assembler;
  76.   Asm
  77.    Push DS           { Push Data Segment                  }
  78.    LDS DX, FileName  { Nul Terminated String of FileName  }
  79.    Inc DX            { Get Rid of Length Byte             }
  80.    Mov AH, 43h       { Dos Function 43h, File Change Mode }
  81.    Mov AL, 1         { Change Attributes                  }
  82.    Mov CX, 0         { Nothing, UnEverything it           }
  83.    Int 21h           { Call Dos                           }
  84.    JC @Done          { See if there was an error          }
  85.    Mov AL, 0         { If not, then no error              }
  86.   @Done:
  87.    Pop DS            { Pop Data Segment                   }
  88.   End;
  89.  
  90.  Function FileAttributes(FileName : String) : Integer; Assembler;
  91.   Asm
  92.    Push DS           { Push Data Segment                  }
  93.    LDS DX, FileName  { Nul Terminated String of FileName  }
  94.    Inc DX            { Get Rid of Length Byte             }
  95.    Mov AH, 43h       { Dos Function 43h, File Change Mode }
  96.    Mov AL, 0         { Return Attributes                  }
  97.    Int 21h           { Call Dos                           }
  98.    JC @Error         { See if there was an error          }
  99.    Mov AX, CX        { Return Attributes                  }
  100.    Jmp @Done
  101.   @Error:
  102.    Mov AX, -1        { Return -1 For Error                }
  103.   @Done:
  104.    Pop DS            { Pop Data Segment                   }
  105.   End;
  106.  
  107. End.
  108.